/*Copyright (c) 2009 Michael Streif
 *
 *Permission is hereby granted, free of charge, to any person obtaining a copy
 *of this software and associated documentation files (the "Software"), to deal
 *in the Software without restriction, including without limitation the rights
 *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *copies of the Software, and to permit persons to whom the Software is
 *furnished to do so, subject to the following conditions:
 *
 *The above copyright notice and this permission notice shall be included in
 *all copies or substantial portions of the Software.
 *
 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *THE SOFTWARE.
 */

#include "printk.h"
#include "pic.h"
#include "idt.h"
#include "asm.h"
#include "multiboot.h"
#include "vmm.h"
#include "physmm.h"
#include "types.h"
#include "kmalloc.h"
#include "textmode.h"
#include "console.h"

/*#include "fonts.h"

unsigned int* video;

#define VIDMEM_START 0x200000

void putPixel(unsigned int argb, int x, int y)
{
	if ((x < 800) && (y < 600))
		*(video + y * xres + x) = argb;
}

void drawRect(int x, int y, int width, int height)
{
	for (int i = x+width-1; i >= x; i--)
	{
		for (int j = y+height-1; j >= y; j--)
		{
			putPixel(0xFFFFFFFF, i, j);
		}
	}
}

void printChar(unsigned int character, int x, int y)
{
	unsigned char currentRow = 0;

	for (int i = 0; i < 8; i++)
	{
		currentRow = font1[i+character*8];

		for (int j = 0; j < 8; j++)
		{
			if ((currentRow & 128) == 128)
			{
				putPixel(0xFFFFFFFF, j+x, i+y);
			}

			currentRow = currentRow << 1;
		}
	}
}

void printf(char* string)
{
	while (*string != '\0')
	{
		printChar(*string, 10, 10);
		string++;
	}
}*/

extern uint64 kernelEnd;

void kmain(multibootInfo* mbInfo)
{
	clearscreen();

	initPIC(0x20, 0x28);

	setupIDT();

	enableINTS();

	SetupPhysMM(mbInfo);

	setupConsole(20);

	disableINTS();

	maskIRQ(0xFD, 0xFF);

	enableINTS();

	printPgFrameStack();

	printGrubMemMap(mbInfo);

	while(1)
	{
		__asm__("hlt");
	}
}






